package com.oa.co.controller;


import com.github.pagehelper.PageInfo;
import com.oa.co.common.PageVo;
import com.oa.co.pojo.Goods;
import com.oa.co.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin("*")
@RequestMapping("/goods")
@RestController   // =  @ResponseBody + @Controller
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @RequestMapping("/selectGoods")
    public PageVo<Goods> selectGoods(Integer page,Integer limit,Integer goods_id, String goods_name) {


        PageVo<Goods> pageVo = new PageVo<>();
        
        //使用 mybatis的分页插件
        PageInfo<Goods> pageData = goodsService.getPageData(page, limit, goods_id, goods_name);

        // 把分页查询结果 封装到 layui 的 列表组件支持的数据结构中
        pageVo.setData(pageData.getList());

        pageVo.setCode(0);

        pageVo.setCount(pageData.getTotal());

        pageVo.setMsg("物品分页数据");
        return pageVo;
    }

}
